<script setup lang="ts">
import { reactive } from 'vue';
import { useRouter } from 'vue-router';
import { message } from 'ant-design-vue';

const router = useRouter();

interface FormState {
  name: string;
  password: string;
}

const formState = reactive<FormState>({
  name: 'admin',
  password: 'admin',
});

const onFinish = (values: any) => {
  const { name, password } = values;
  if (name != 'admin') {
    message.error('用户名错误，请重新输入！');
    return;
  } else if (password != 'admin') {
    message.error('密码错误，请重新输入！');
    return;
  } else {
    message.success('登录成功！');
    router.push({
      name: 'work-distribution',
    });
  }
};

const onFinishFailed = (errorInfo: any) => {
  // console.log('Failed:', errorInfo);
};
</script>

<template>
  <div class="wp">
    <div class="loginBox">
      <h2 class="title">农房乱占耕地核查系统</h2>
      <div class="formBox">
        <a-form
          :model="formState"
          name="basic"
          :label-col="{ span: 5 }"
          autocomplete="off"
          @finish="onFinish"
          @finishFailed="onFinishFailed"
        >
          <a-form-item
            label="用户名："
            name="name"
            :rules="[
              { required: true, message: '请输入用户名！', trigger: 'blur' },
            ]"
          >
            <a-input v-model:value="formState.name" />
          </a-form-item>

          <a-form-item
            label="密码："
            name="password"
            :rules="[
              { required: true, message: '请输入密码！', trigger: 'blur' },
            ]"
          >
            <a-input-password v-model:value="formState.password" />
          </a-form-item>

          <a-form-item :wrapper-col="{ offset: 5 }">
            <a-button
              type="primary"
              html-type="submit"
              style="width: 200px; margin-top: 20px"
              >登录</a-button
            >
          </a-form-item>
        </a-form>
      </div>
    </div>
  </div>
</template>

<style scoped lang="less">
.wp {
  width: 100%;
  min-height: 100vh;
  background: #293146;
  display: flex;
  justify-content: center;
  align-items: center;
  background: url('@/assets/bg.jpg') no-repeat;
  background-size: cover;
  .loginBox {
    width: 60%;
    max-width: 400px;
    min-height: 350px;
    overflow: hidden;
    border-radius: 4px;
    padding: 24px;
    background: rgba(255, 255, 255, 0.9);
    .title {
      width: 100%;
      padding: 25px 0;
      font-size: 28px;
      text-align: center;
      margin-top: 10px;
    }
    .formBox {
      width: 90%;
      margin: 0 auto;
    }
  }
}
</style>
